package com.dushuren.project.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * 时间工具类
 */
public class DatesUtils {

  /**
   * 当月第一天
   * @return
   */
  public static String getFirstDay() {
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	Calendar calendar = Calendar.getInstance();
	Date theDate = calendar.getTime();

	GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
	gcLast.setTime(theDate);
	gcLast.set(Calendar.DAY_OF_MONTH, 1);
	String day_first = df.format(gcLast.getTime());
	StringBuffer str = new StringBuffer().append(day_first).append(" 00:00:00");
	return str.toString();

  }

  /**
   * 当月最后一天 最后1秒
   * @return
   */
  public static String getLastDay() {
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	Calendar calendar = Calendar.getInstance();
	Date theDate = calendar.getTime();
	String s = df.format(theDate);
	calendar.add(Calendar.MONTH, 1);    //加一个月
	calendar.set(Calendar.DATE, 1);        //设置为该月第一天
	calendar.add(Calendar.DATE, -1);    //再减一天即为上个月最后一天
	String day_last = df.format(calendar.getTime());
	StringBuffer endStr = new StringBuffer().append(day_last);
	day_last = endStr.toString();
	StringBuffer str = new StringBuffer().append(day_last).append(" 23:59:59");
	return str.toString();
  }
}
